<?php 


require "../common/Curl.php";

/**
 *	https://open.esign.cn/doc/detail?id=opendoc%2Fpaas_api%2Fsgv49u&namespace=opendoc%2Fpaas_api
 * 	电子签名SaaS API非标版
 * 	印章服务API----接口顺序排列封装
 *  使用请求签名鉴权方式
 *  下一个------------------ 印章服务sealhelp.php
 */


//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [createSealPerson 创建个人模板印章]
 * @param  [type] $accountId [个人账号accountId]
 * @param  [type] $color     [印章颜色]
 * @param  [type] $type      [模板类型]
 * @param  [type] $alias     [印章别名]
 * @param  [type] $height    [高度]
 * @param  [type] $width     [宽度]
 * @param  [type] $header    [请求头]
 * @param  string $url       [请求地址]
 * @return [json]            [返回印章链接信息等等]
 */
function createSealPerson($accountId,$color,$type,$alias,$height,$width,$appId,$secret,$url){
	$urlss = $url."/v1/accounts/".$accountId."/seals/personaltemplate";
	$head_url = "/v1/accounts/".$accountId."/seals/personaltemplate";
	$data = [
		'accountId'=>$accountId,
		"color"=>$color,
	    "type"=>$type,
	    "alias"=>$alias,
	    "height"=>$height,
	    "width"=>$width
	];
    $res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}
$accountId = "5539bd029e4e45f4b2095aacbcf1ea19";   //用户id
$color = "BLUE";   // 印章颜色，RED-红色  BLUE-蓝色 BLACK-黑色
$type = "BORDERLESS";  //  SQUARE 正方形印章  RECTANGLE 带边框矩形印章  BORDERLESS 无边框矩形印章
$alias = "刘颂晶";      //印章别名
$width = "100";
$height = "100";    //印章宽高
$a = createSealPerson($accountId,$color,$type,$alias,$height,$width,$appId,$secret,$url);
var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [createSealOrgan 创建机构模板印章]
 * @param  [type] $orgId   [机构账号orgId]
 * @param  [type] $color   [印章颜色]
 * @param  [type] $type    [模板类型]
 * @param  [type] $central [中心图案类型]
 * @param  [type] $alias   [印章别名]
 * @param  [type] $height  [高度]
 * @param  [type] $width   [宽度]
 * @param  [type] $htext   [横向文]
 * @param  [type] $qtext   [下弦文]
 * @param  [type] $header  [请求头]
 * @param  string $url     [请求地址]
 * @return [json]          [返回印章链接信息等等]
 */
function createSealOrgan($orgId,$color,$type,$central,$alias,$height,$width,$htext,$qtext,$appId,$secret,$url){
	$urlss = $url."/v1/organizations/".$orgId."/seals/officialtemplate";
	$head_url = "/v1/organizations/".$orgId."/seals/officialtemplate";
	$data = [
		'orgId'=>$orgId,
		"color"=>$color,
	    "type"=>$type,
	    "central"=>$central,
	    "alias"=>$alias,
	    "height"=>$height,
	    "width"=>$width,
	    "htext"=>$htext,
	    "qtext"=>$qtext
	];
	$res = json_encode($data);
    $header = getHeader($data,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}
// $orgId = "6f69dc0a5c8d415aa6a0c7e239a32241";   //机构id
// $color = "RED";   // 印章颜色，RED-红色  BLUE-蓝色 BLACK-黑色
// $type = "TEMPLATE_ROUND";  //  TEMPLATE_ROUND 圆章   TEMPLATE_OVAL 	椭圆章 
// $central = "STAR";     // STAR 圆形有五角星   NONE 圆形无五角星
// $alias = "刘颂晶机构的专属印章";      //印章别名
// $width = "100";
// $height = "100";    //印章宽高
// $htext = "lsj";  // 横向文
// $qtext = "刘颂晶科技有限公司"; //下弦文
// $a = createSealOrgan($orgId,$color,$type,$central,$alias,$height,$width,$htext,$qtext,$appId,$secret,$url);
// var_dump($a);die;

//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/**
 * [createSealImage 创建个人、机构图片印章]
 *      这里需要将png图片转为base64格式
 * @param  [type] $accountId       [用户id]
 * @param  [type] $type            [印章数据类型，BASE64：base64格式]
 * @param  [type] $data            [印章数据，目前只支持png格式，base64格式字符串，不包含格式前缀]
 * @param  [type] $alias           [印章别名]
 * @param  [type] $height          [印章高度]
 * @param  [type] $width           [宽度]
 * @param  [type] $transparentFlag [是否对图片进行透明化处理，默认false。]
 * @return [json]                  [返回图片下载链接]
 */
function createSealImage($accountId,$type,$data,$alias,$height,$width,$transparentFlag,$appId,$secret,$url){
	$urlss = $url."/v1/accounts/".$accountId."/seals/image";
	$head_url = "/v1/accounts/".$accountId."/seals/image";
	$dataes = [
		'accountId'=>$accountId,
	    "type"=>$type,
	    "data"=>$data,
	    "alias"=>$alias,
	    "height"=>$height,
	    "width"=>$width,
	    "transparentFlag"=>$transparentFlag
	];
	$res = json_encode($dataes);
    $header = getHeader($dataes,"POST",$head_url,$appId,$secret,$url);
    $result = sendHttp($method="POST",$urlss,$header,$res);
    return $result;
}
// $accountId = "5539bd029e4e45f4b2095aacbcf1ea19";
// $alias = "图片印章1";
// $data = "iVBORw0KGgoAAAANSUhEUgAAABsAAAAZCAYAAADAHFVeAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADNSURBVEhLY3jKIPSfXnjUMqpgTMuYRP5/KKqG4xeKhnC5l9pWKHL48BvfSFRzgRjTMlbx/8jgjXcEXO5dUi5UlDD4tnYTqrlAPHgtexuW9P/PoydE4S8zF6CaC8QkWUYpHrUMjN/4RP7/efw0UfhTez+quUBMkmXDN+m/MnX+/7lnClH4XVwmqrlAPHgTCKWYJMueccv8fyGrSxR+LqKCai4QD94EMsQtYwQmcXNXOH4moAiXey6qiiKHD79QNUE1F4gxLaMhHq6WCf0HADhrew7JsbXmAAAAAElFTkSuQmCC";
// $height = "100";
// $width = "100";
// $type = "BASE64";
// $a = createSealImage($accountId,$type,$data,$alias,$height,$width,$transparentFlag,$appId,$secret,$url);
// var_dump($a);die;


